package com.samuel.basics.init;

import com.samuel.basics.cache.MybatisRedisCache;
import com.samuel.basics.utils.SpringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * <p></p>
 *
 * @author aneng huang
 * @since 2020-12-29 10:36:25
 */
@Component
@Order(value = 1)
public class InitCommand implements CommandLineRunner {

    private static final Logger logger = LoggerFactory.getLogger(InitCommand.class);

    private RedisTemplate<String, Object> redisTemplate;

    @Override
    @SuppressWarnings("all")
    public void run(String... args) throws Exception {
        if (redisTemplate == null) {
            logger.info("初始化redisTemplate");
            redisTemplate = (RedisTemplate<String, Object>) SpringUtil.getBean("redisTemplate");
            MybatisRedisCache.setRedisTemplate(redisTemplate);
        }
    }
}
